//
//  BookCityView.m
//  WNZSSQ
//
//  Created by JDKJ on 2018/12/5.
//  Copyright © 2018年 JDKJ. All rights reserved.
//

#import "BookCityView.h"

@interface BookCityView ()<FSSegmentTitleViewDelegate>

@end

@implementation BookCityView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        //选择1
        FSSegmentTitleView *seletTitleView1 = [[FSSegmentTitleView alloc]init] ;
        seletTitleView1.delegate = self;
        seletTitleView1.titlesArr = @[@"全部",@"都是",@"悬疑",@"言情",@"武侠",@"灵域",@"动漫",@"科幻",@"大片"];
        seletTitleView1.indicatorType =  FSIndicatorTypeCustom;
        seletTitleView1.itemMargin = 30;
        seletTitleView1.titleSelectFont = MidFont;
        seletTitleView1.titleFont = MidFont;
        seletTitleView1.titleNormalColor = CSColorFromRGB(0x6B6763);
        seletTitleView1.titleSelectColor = CSColorFromRGB(0xF52C50);
        seletTitleView1.indicatorColor = CSColorFromRGB(0xF5F5F5);
        seletTitleView1.backgroundColor = CSClearColor;
        seletTitleView1.indicatorExtension = 15;
        seletTitleView1.indicatorView.layer.cornerRadius = 15;
        seletTitleView1.indicatorView.clipsToBounds = YES;
        seletTitleView1.selectIndex = 0;
        self.seletTitleView1 = seletTitleView1;
        [self addSubview:seletTitleView1];
        
        

        //选择2
        FSSegmentTitleView *seletTitleView2 = [[FSSegmentTitleView alloc]init] ;
        seletTitleView2.titlesArr = @[@"全部",@"热门",@"最新"];
        seletTitleView2.delegate = self;
        seletTitleView2.indicatorType =  FSIndicatorTypeCustom;
        seletTitleView2.itemMargin = 30;
        seletTitleView2.titleSelectFont = MidFont;
        seletTitleView2.titleFont = MidFont;
        seletTitleView2.titleNormalColor = CSColorFromRGB(0x6B6763);
        seletTitleView2.titleSelectColor = CSColorFromRGB(0xF52C50);
        seletTitleView2.indicatorColor = CSColorFromRGB(0xF5F5F5);
        seletTitleView2.backgroundColor = CSClearColor;
        seletTitleView2.indicatorExtension = 15;
        seletTitleView2.indicatorView.layer.cornerRadius = 15;
        seletTitleView2.indicatorView.clipsToBounds = YES;
        seletTitleView2.selectIndex = 0;
        self.seletTitleView2 = seletTitleView2;
        [self addSubview:seletTitleView2];

        //选择3
        FSSegmentTitleView *seletTitleView3 = [[FSSegmentTitleView alloc]init] ;
        seletTitleView3.titlesArr = @[@"全部",@"连载",@"完结"];
        seletTitleView3.delegate = self;
        seletTitleView3.indicatorType =  FSIndicatorTypeCustom;
        seletTitleView3.itemMargin = 30;
        seletTitleView3.titleSelectFont = MidFont;
        seletTitleView3.titleFont = MidFont;
        seletTitleView3.titleNormalColor = CSColorFromRGB(0x6B6763);
        seletTitleView3.titleSelectColor = CSColorFromRGB(0xF52C50);
        seletTitleView3.indicatorColor = CSColorFromRGB(0xF5F5F5);
        seletTitleView3.backgroundColor = CSClearColor;
        seletTitleView3.indicatorExtension = 15;
        seletTitleView3.indicatorView.layer.cornerRadius = 15;
        seletTitleView3.indicatorView.clipsToBounds = YES;
        seletTitleView3.selectIndex = 0;
        self.seletTitleView3 = seletTitleView3;
        [self addSubview:seletTitleView3];

        //选择4
        FSSegmentTitleView *seletTitleView4 = [[FSSegmentTitleView alloc]init] ;
        seletTitleView4.titlesArr = @[@"全部",@"30万以下",@"30-50万字",@"50-100万字",@"100万字以上"];
        seletTitleView4.indicatorType =  FSIndicatorTypeCustom;
        seletTitleView4.delegate = self;
        seletTitleView4.itemMargin = 30;
        seletTitleView4.titleSelectFont = MidFont;
        seletTitleView4.titleFont = MidFont;
        seletTitleView4.titleNormalColor = CSColorFromRGB(0x6B6763);
        seletTitleView4.titleSelectColor = CSColorFromRGB(0xF52C50);
        seletTitleView4.indicatorColor = CSColorFromRGB(0xF5F5F5);
        seletTitleView4.backgroundColor = CSClearColor;
        seletTitleView4.indicatorExtension = 15;
        seletTitleView4.indicatorView.layer.cornerRadius = 15;
        seletTitleView4.indicatorView.clipsToBounds = YES;
        seletTitleView4.selectIndex = 0;
        self.seletTitleView4 = seletTitleView4;
        [self addSubview:seletTitleView4];
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    //选择1
    [self.seletTitleView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self).offset(-15);
        make.left.mas_equalTo(self).offset(15);
        make.top.mas_equalTo(self).offset(15);
        make.height.mas_equalTo(30);
        
    }];
    
    UIButton *btn1 = (UIButton *)[self.seletTitleView1 viewWithTag:666];
    
    [self.seletTitleView1.indicatorView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(btn1);
        
        
    }];
    
    //选择2
    [self.seletTitleView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self.seletTitleView1);
        make.top.mas_equalTo(self.seletTitleView1.mas_bottom).offset(12);
        make.height.mas_equalTo(30);
        
    }];
    UIButton *btn2 = (UIButton *)[self.seletTitleView2 viewWithTag:666];
    
    [self.seletTitleView2.indicatorView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(btn2);
        
    }];
    
    //选择3
    [self.seletTitleView3 mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self.seletTitleView1);
        make.top.mas_equalTo(self.seletTitleView2.mas_bottom).offset(12);
        make.height.mas_equalTo(30);
        
    }];
    
    UIButton *btn3 = (UIButton *)[self.seletTitleView3 viewWithTag:666];
    
    [self.seletTitleView3.indicatorView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(btn3);
        
    }];
    
    //选择4
    [self.seletTitleView4 mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self.seletTitleView1);
        make.top.mas_equalTo(self.seletTitleView3.mas_bottom).offset(12);
        make.height.mas_equalTo(30);
        make.bottom.mas_equalTo(self);
        
    }];
    
    UIButton *btn4 = (UIButton *)[self.seletTitleView4 viewWithTag:666];
    
    [self.seletTitleView4.indicatorView mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.edges.mas_equalTo(btn4);
        


    }];
    
}


#pragma mark FSSegmentTitleViewDelegate

- (void)FSSegmentTitleView:(FSSegmentTitleView *)titleView startIndex:(NSInteger)startIndex endIndex:(NSInteger)endIndex
{
    
    UIButton *btn4 = (UIButton *)[titleView viewWithTag:666 +endIndex];
    
    [titleView.indicatorView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(btn4);
        
        
        
    }];
    
}


@end

@implementation BookCityViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        //封面
        UIImageView *covImageView = [[UIImageView alloc]init];
        covImageView.image = PlaceHold4;
        covImageView.contentMode = UIViewContentModeScaleAspectFill;
        covImageView.clipsToBounds = YES;
        self.covImageView = covImageView;
        [self addSubview:covImageView];
        
        //书名
        UILabel *titleLable = [[UILabel alloc]init];
        titleLable.text = @"极品女上";
        titleLable.numberOfLines = 2;
        titleLable.textColor = CSBlackColor1;
        titleLable.font = MidFont;
        self.titleLable = titleLable;
        [self addSubview:titleLable];
        
        //作者
        UILabel *nameLable = [[UILabel alloc]init];
        nameLable.text = @"唐家三少";
        nameLable.textColor = CSColorFromRGB(0x6B6763);
        nameLable.font = SmallFont;
        self.nameLable = nameLable;
        [self addSubview:nameLable];
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    //封面
    
    CGFloat itemWitW = (SCREEN_WIDTH - 90) / 3;
    [self.covImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.mas_equalTo(self);
        make.width.mas_equalTo(itemWitW);
        make.height.mas_equalTo(itemWitW/3*4);
        
    }];
    
    //书名
    [self.titleLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.covImageView.mas_bottom).offset(8);
        make.left.right.mas_equalTo(self.covImageView);
        
    }];
    
    //作者
    [self.nameLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.titleLable.mas_bottom).offset(8);
        make.left.right.mas_equalTo(self.covImageView);
        make.bottom.mas_equalTo(self);
        
    }];
    
}

@end
